package com.ebt.m.customer.util;

import android.os.Handler;
import android.os.Message;

import com.ebt.m.customer.constant.CustomerConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by Rick.Wang on 2017/1/10.
 */

public class MultiChooseManager {

    private static MultiChooseManager instance;

    private HashMap<Object, Boolean> flags = new HashMap<>();
    private boolean inMultiChooseMode = false;
    private List<Object> all = new ArrayList<>();

    private MultiChooseManager(){}

    public static MultiChooseManager getInstance(){
        if (instance == null) {
            synchronized (MultiChooseManager.class) {
                if (instance == null) {
                    instance = new MultiChooseManager();
                }
            }
        }
        return instance;
    }

    public void setFlag(Object o, Boolean b){
        flags.put(o, b);
    }

    public boolean getFlag(Object o){
        Boolean b = flags.get(o);
        if (b == null){
            return false;
        }
        return b;
    }

    public void clearFlags(){
        flags.clear();
    }

    public void setInMultiChooseMode(boolean b){
        inMultiChooseMode = b;
    }

    public boolean getInMultiChooseMode(){
        return inMultiChooseMode;
    }

    public HashMap<Object, Boolean> getFlags(){
        return flags;
    }

    public List<Object> getSelectedObjects(){
        List<Object> list = new ArrayList<>();
        Set<Map.Entry<Object, Boolean>> set = flags.entrySet();
        for (Map.Entry<Object, Boolean> e : set){
            if (e.getValue() == null || e.getValue() == false){
                continue;
            }
            list.add(e.getKey());
        }
        return list;
    }

    public boolean checkIfAllSelected(){
        return (getSelectedObjects().size() == all.size());
    }

    public int getAllSize(){
        return all.size();
    }

    public void setAllUuids(List<String> uuids){
        all.clear();
        if (uuids != null) {
            for (String item : uuids) {
                all.add(item);
            }
        }
    }

    public void selectAll(){
        flags.clear();
        for(Object item : all) {
            flags.put(item, true);
        }
    }
}